﻿using System;
using GeoAPI.Geometries;

namespace NetTopologySuite.Geometries.Utilities
{
	public abstract class ShortCircuitedGeometryVisitor
	{
		public void ApplyTo(IGeometry geom)
		{
			int num = 0;
			while (num < geom.NumGeometries && !this._isDone)
			{
				IGeometry geometryN = geom.GetGeometryN(num);
				if (!(geometryN is IGeometryCollection))
				{
					this.Visit(geometryN);
					if (this.IsDone())
					{
						this._isDone = true;
						return;
					}
				}
				else
				{
					this.ApplyTo(geometryN);
				}
				num++;
			}
		}

		protected abstract void Visit(IGeometry element);

		protected abstract bool IsDone();

		private bool _isDone;
	}
}
